package ce51.dunghn.chatslide;

import br.com.dina.ui.widget.UITableView_User;


import vg.com.chatonline.activity.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

public class SampleFragment extends Fragment {
	private DiscussArrayAdapter adapter;
	private ListView lv;
	private EditText editText1;
	private UITableView_User tableView;

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.activity_center, null);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		adapter = new DiscussArrayAdapter(getActivity(),
				R.layout.listitem_discuss);
		lv = (ListView) getView().findViewById(R.id.listView1);
		LinearLayout layout=(LinearLayout)getView().findViewById(R.id.layout_top_chat);
		layout.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(getActivity(), "layout", Toast.LENGTH_SHORT).show();
			}
		});
		lv.setAdapter(adapter);
		lv.setSelection(lv.getAdapter().getCount()-1);

		editText1 = (EditText) getView().findViewById(R.id.edt_chat);
		Button btn1 = (Button) getView().findViewById(R.id.btn1);
		Button btn2 = (Button) getView().findViewById(R.id.btn2);
		btn1.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!editText1.getText().toString().equals("")) {
					adapter.add(new OneComment(true, editText1.getText()
							.toString()));
					editText1.setText("");
					lv.setSelection(lv.getAdapter().getCount()-1);
					hide(getActivity());
				}
			}
		});
		btn2.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (!editText1.getText().toString().equals("")) {
					adapter.add(new OneComment(false, editText1.getText()
							.toString()));
					editText1.setText("");
					lv.setSelection(lv.getAdapter().getCount()-1);
					hide(getActivity());
				}
			}
		});
	}
	public void hide(Activity activity) {
	    InputMethodManager inputMethodManager = (InputMethodManager)  activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
	    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
	}
	
	private void createList() {
		//CustomClickListener listener = new CustomClickListener();
    	//tableView.setClickListener(listener);
//		tableView.addBasicItem(R.drawable.add_contact, "Trang cá nhân", "");
//		tableView.addBasicItem(R.drawable.add_user_goi_y, "Thay đổi tài khoản", "");
		tableView.addBasicItem(R.drawable.us_account, "Trang cá nhân", "");
//		tableView.addBasicItem(R.drawable.us_edit, "Chỉnh Sửa Thông Tin", "");
//		tableView.addBasicItem(R.drawable.us_logout, "Thay đổi tài khoản", "");
//		tableView.addBasicItem(R.drawable.us_product, "Sản Phẩm", "");
//		tableView.addBasicItem(R.drawable.us_close, "Thoát Ứng Dụng", "");

	}
}
